﻿using System;
using WordContentControl = Microsoft.Office.Interop.Word.ContentControl;

namespace CodeCounsel.Office.DatabindingToolkit
{
    public class ContentControl
    {
        WordContentControl _wordContentControl = null;

        public string ID
        {
            get { return _wordContentControl.ID; }
        }

        public ContentControl(WordContentControl wordContentControl)
        {
            _wordContentControl = wordContentControl;
        }

        public void SetXPathBinding(CustomXmlNode node)
        {
            _wordContentControl.XMLMapping.SetMapping(
                node.XPath, 
                String.IsNullOrEmpty(node.NamespaceUri) == false ?
                    CreateNamespacePrefix(node) : null, 
                node.Owner.WordXmlPart);
        }

        private string CreateNamespacePrefix(CustomXmlNode node)
        {
            return String.Format("xmlns:{0}='{1}'",
                node.Owner.LookupPrefix(node.NamespaceUri),
                node.NamespaceUri);
        }
    }
}
